const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
const webpack = require('webpack');

module.exports = {
    entry: {
        app: './src/index.js',
        // print: './src/print.js'
    },
    output: {
        filename: '[name].bundle.[hash:4].js',
        path: path.resolve(__dirname, 'dist'),
        // publicPath: '/'
    },
    devtool: 'inline-source-map',
    devServer: {
        // inline: true,
        historyApiFallback: true, //不跳转,让所有的404定位到index;
        contentBase: './dist',
        hot: true,
        // publicPath: '/',
        // hotOnly: true
    },
    module: {
        rules: [
            {
                test: /\.css$/,
                use: [
                    'style-loader',
                    'css-loader'
                ]
            },
            // {
            //     test: /\.(png|svg|jpg|gif)$/,
            //     use: [
            //         'file-loader'
            //     ]
            // },
            // {
            //     test: /\.(woff|woff2|eot|ttf|otf)$/,
            //     use: [
            //         'file-loader'
            //     ]
            // },
        ]
    },
    plugins: [
        new CleanWebpackPlugin(),
        new HtmlWebpackPlugin({
            title: 'output manage',
            template: './index.html',//html文件的模板
            // hash: true,
            // minify: {    //压缩HTML文件
            //     removeComments: true,    //移除HTML中的注释
            //     collapseWhitespace: true    //删除空白符与换行符
            // }
        }),
        new webpack.NamedModulesPlugin(),
        new webpack.HotModuleReplacementPlugin()
    ]
};